const getWeChatCode = () => {
  // 构建微信授权链接
  const redirectUrl = encodeURIComponent(window.location.href);
  const wechatAuthUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=YOUR_APPID&redirect_uri=${redirectUrl}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`;

  // 重定向到微信授权链接
  window.location.href = wechatAuthUrl;
}

const wechatLogin = () => {
  const urlParams = new URLSearchParams(window.location.search);

  if (urlParams.has('code')) {
    const code = urlParams.get('code');
    sessionStorage.setItem('WECHAT_CODE', code);
  } else {
    getWeChatCode();
  }
}
